package m.system.handler;

import m.system.util.AnnotationUtil;
import m.system.util.ClassUtil;
import m.system.util.StringUtil;

import java.util.List;
import java.util.Map;

public class InitHandler {
    public static void init(String handlerPack) throws ClassNotFoundException {
        if(StringUtil.isSpace(handlerPack)) return ;
        String[] packs=StringUtil.toArrayDedup(handlerPack,",");
        for (String pack : packs) {
            if (StringUtil.isSpace(pack)) continue;
            List<String> modelNames = ClassUtil.getAllQualifiedName4Class(pack);
            for (String modelName : modelNames) {
                Class<?> clazz = Class.forName(modelName);
                Map<String,HandlerMethodMeta> map= AnnotationUtil.getAnnotationMap4Method(HandlerMethodMeta.class,clazz);
                for(String key : map.keySet()){
                    HandlerMethodMeta meta=map.get(key);
                    HandlerUtil.addHandler(meta,clazz,key);
                }
            }
        }
    }
}
